<?php


mysql_connect("sql.gruper.pl", "webdomain_002", "BO5qaDr4");
mysql_select_db("webdomain_002");

$res1 = mysql_query("select id, assigned_user_id from accounts");

while ($row1 = mysql_fetch_assoc($res1))
{
    $res2 = mysql_query("SELECT c.id from grp_cities c JOIN grp_cities_users cu ON c.id = cu.grp_city_id WHERE cu.user_id = '".$row1['assigned_user_id']."' LIMIT 1");

    echo "SELECT c.id from grp_cities c JOIN grp_cities_users cu ON c.id = cu.grp_city_id WHERE cu.user_id = '".$row1['assigned_user_id']."' LIMIT 1<br/>";

    if ($row2 = mysql_fetch_assoc($res2)){
        
        echo "update";

        mysql_query("UPDATE accounts SET city_id = '".$row2['id']."' WHERE id = '".$row1['id']."' LIMIT 1");
        echo "UPDATE accounts SET city_id = '".$row2['id']."' WHERE id = '".$row1['id']."' LIMIT 1<br/>";
        
    } else {

        mysql_query("UPDATE accounts SET city_id = '' WHERE id = '".$row1['id']."' LIMIT 1");
        

    }

    
}

?>
